//
// Created by hjie on 23-5-3.
//

#pragma once

#include <string>
#include <memory>
#include "data_buffer.h"
#include "define.h"
#include "tcp_socket.h"

class Channel;
class LoopEvent;
class Server;
class Connection;

class Connection {
    friend class Server;
public:
    Connection(LoopEvent * loop, int socket, WriteAbleCallback && w_func, ReadAbleCallback && r_func, ErrorCallback && e_func);
    ~Connection();
    void RegisterChannel(int event_type);
    int64_t ChannelId();
    std::size_t SendData(const std::string & data);
    std::size_t SendData(const uint8_t * data, std::size_t size);
    void CloseConnection();
    void RemoveBufferData(int size);
private:
    LoopEvent * m_loop_event;
    std::shared_ptr<Channel> m_connection_channel;
    TcpSocket * m_socket;
public:
    DataBuffer * m_data_buffer;
};


